/*
 * @Author: AI Assistant
 * @Date: 2024-12-19
 * @Description: 模型管理数据模型
 */
import { ApiProperty } from '@nestjs/swagger';
import { modelOptions, prop } from '@typegoose/typegoose';
import { IsNotEmpty, Allow, IsOptional, IsIn } from 'class-validator';

@modelOptions({
  // 自动为每个属性添加时间戳
  schemaOptions: {
    timestamps: true,
  },
})
export class Module {
  @ApiProperty({ description: '模型名称' })
  @IsNotEmpty({ message: '模型名称不能为空' })
  @prop()
  moduleName: string;

  @ApiProperty({ description: '模型类型', enum: ['list', 'page', 'category', 'detail'] })
  @IsNotEmpty({ message: '模型类型不能为空' })
  @IsIn(['list', 'page', 'category', 'detail'], { message: '模型类型只能是list、page、category、detail' })
  @prop()
  moduleType: 'list' | 'page' | 'category' | 'detail';

  @ApiProperty({ description: '模型状态', enum: [0, 1] })
  @IsNotEmpty({ message: '模型状态不能为空' })
  @IsIn([0, 1], { message: '模型状态只能是0或1' })
  @prop()
  status: number;

  @ApiProperty({ description: '列表模板名称', required: false })
  @IsOptional()
  @prop()
  listTemplateName?: string;

  @ApiProperty({ description: '列表模板id', required: false })
  @IsOptional()
  @prop()
  listTemplateId?: string;

  @ApiProperty({ description: '详情模板名称', required: false })
  @IsOptional()
  @prop()
  detailTemplateName?: string;

  @ApiProperty({ description: '详情模板id' })
  @IsNotEmpty({ message: '详情模板id不能为空' })
  @prop()
  detailTemplateId: string;

  @Allow()
  moduleId: string;

  @Allow()
  createdAt: string;

  @Allow()
  updatedAt: string;

  @Allow()
  __v: string;
}